package com.coinland.study.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Build;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;

/**
 * 类描述:  屏幕操作工具
 * 创建人:  shenZ
 * 创建时间: 2020/4/17
 * 联系方式: 252079249@qq.com
 * 修改时间: 2020/4/17
 */
public class ScreenUtils {
    private static final String TAG = ScreenUtils.class.getSimpleName();

    /**
     * view截图
     *
     * @return
     */
    public static void viewShot(Activity context,
                                @Nullable final ShotCallback shotCallback) {

        long startMs = System.currentTimeMillis(); // 起始时间
        View activityView = context.getWindow().getDecorView();
        activityView.setDrawingCacheEnabled(true);
        activityView.destroyDrawingCache();
        activityView.buildDrawingCache();
        Bitmap bitmap = activityView.getDrawingCache();

        Log.d(TAG, "获取屏幕截图所需时间:" + (System.currentTimeMillis() - startMs) + "ms");
        if (null != shotCallback) {
            shotCallback.onShotComplete(bitmap);
        }
    }


    public interface ShotCallback {
        void onShotComplete(Bitmap bitmap);
    }
}
